#include "stdafx.h"
#include "Bullet.h"
#include "Vertex.h"

bool Bullet::loadFile(char szNfg[], char szVS[], char szFS[])
{
	this->loadShader(szVS, szFS);

	return true;
}

bool Bullet::loadShader(char szVS[], char szFS[])
{
	this->m_Shader = new Shaders();
	this->m_Shader->Init(szVS, szFS);
	return true;
}

bool Bullet::init(Vector3 director, Vector3 startPosition, float speed)
{
	this->_director = director;
	this->_startPosition = startPosition;
	this->_speed = speed;
	this->_isActive = false;
	return true;
}

void Bullet::draw()
{
	if (_isActive)
	{
		this->m_Models[0]->draw(m_Shader);
		glActiveTexture(GL_TEXTURE0);
		glBindTexture(GL_TEXTURE_2D, this->m_Models[0]->getTextureID());
		glUniform1i(m_Shader->blendSampler, 0);

		glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, m_Models[0]->IND);
		glDrawElements(GL_TRIANGLES, m_Models[0]->getNumIndices(), GL_UNSIGNED_SHORT, 0);
	}
}

void Bullet::update(float deltatime)
{
	if (_isActive)
	{
		this->m_Position += _director * _speed * deltatime;
	}
}